﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shine.Util.Data
{
    /// <summary>
    /// 数据库字段信息
    /// </summary>
    public class DbFieldInfo
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DbFieldInfo()
        {
            Nullable = true;
            Length = 0;
            IsKey = false;
        }

        /// <summary>
        /// 字段名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 字段类型名称
        /// </summary>
        private string _TypeName = "String";
        /// <summary>
        /// 字段类型名称
        /// </summary>
        public string TypeName
        {
            get { return _TypeName; }
            set
            {
                _TypeName = value;
                _Type = System.Type.GetType("System."+value);
            }
        }

        /// <summary>
        /// 原始的类型名称
        /// </summary>
        public string OriginalTypeName { get; set; }
        
        /// <summary>
        /// 字段类型
        /// </summary>
        private Type _Type = typeof(string);
        /// <summary>
        /// 字段类型
        /// </summary>
        public Type Type
        {
            get { return _Type; }
            set
            {
                _Type = value;
                _TypeName = value.ToString();
            }
        }
        
        /// <summary>
        /// 是否允许为空
        /// </summary>
        public bool Nullable { get; set; }
        
        /// <summary>
        /// 字段长度
        /// </summary>
        public int Length { get; set; }
        
        /// <summary>
        /// 是否为主键
        /// </summary>
        public bool IsKey { get; set; }
    }
}
